﻿using System.Windows;
using System.Windows.Controls;

namespace MC.Warehouse.Core
{
    public class BaseDataTemplateSelector : DataTemplateSelector
    {
        //public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        //{
        //    var data = item as XmlLinkedNode;
        //    FrameworkElement element = container as FrameworkElement;
        //    if (data.Attributes.Count==0)
        //    {
        //        return element.FindResource("XMLSeparatorTemplate") as DataTemplate;
        //    }
        //    return element.FindResource("XMLToolBarItemTemplate") as DataTemplate;
        //}

        public override DataTemplate SelectTemplate(object barItem, DependencyObject container)
        {
            var data = barItem as Item;
            var element = container as FrameworkElement;
            if (data != null && data.Text == null)
            {
                if (element != null) return element.FindResource("XmlSeparatorTemplate") as DataTemplate;
            }
            if (element != null) return element.FindResource("XmlToolBarItemTemplate") as DataTemplate;
            return null;
        }
    }
}
